﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Design Pattern</title>
    <meta name="language" content="en" />
    <!--myInjectedScript-->
</head>
<body>
    <h1>
        Chain</h1>
    <div class="section">
        <h2>
            Intent</h2>
        <p>
            Avoid coupling the sender of a request to its receiver by giving more than one object
            a chance to handle the request.
            <br />
            Chain the receiving objects and pass the request along the chain until an object
            handles it.
        </p>
    </div>
    <div class="section">
        <h2>
            Motivation</h2>
        <p>
            Decouple senders and receivers by giving multiple objects achance to handle a request.
            <br />
            The request gets passed along a chain of objects until one of them handles it.
            <br />
            <a href="http://en.wikipedia.org/wiki/Chain_pattern" target="_blank">Online resources</a>
        </p>
    </div>
    <div class="section">
        <h2>
            Applicability</h2>
        <p>
            <ol>
                <li>more than one object may handle a request, and the handler isn't known a priori.
                    The handler should be ascertained automatically.</li>
                <li>you want to issue a request to one of several objects without specifying the receiver
                    explicitly.</li>
                <li>the set of objects that can handle a request should be specified dynamically</li>
            </ol>
        </p>
    </div>
    <div class="section">
        <h2>
            Class Diagram</h2>
        <p>
            <img alt="Diagram" src=" chain.png" border="0" />
        </p>
    </div>
    <div class="section">
        <h2>
            Collaborations</h2>
        <p>
            When a client issues a request, the request propagates along the chain until a ConcreteHandler
            object takes responsibility for handling it.<br />
        </p>
    </div>
    <div class="section">
        <h2>
            Consequences</h2>
        <p>
            <ol>
                <li>Reduced coupling.The pattern frees an object from knowing which other object handles
                    arequest. An object only has to know that a request will be handled "appropriately".
                    Both the receiver and the sender have no explicit knowledge of each other, and an
                    object in the chain doesn't have to know about the chain's structure.
                    <br />
                    As a result, Chain of Responsibility can simplify object interconnections. Instead
                    of objects maintaining references to all candidate receivers, they keep a single
                    reference to their successor.</li>
                <li>Added flexibility in assigning responsibilities to objects.Chain of Responsibility
                    gives you added flexibility in distributing responsibilities among objects. You
                    can add or change responsibilities for handling a request by adding to or otherwise
                    changing the chain at run-time. You can combine this with subclassing to specialize
                    handlers statically. </li>
                <li>Receipt isn't guaranteed.Since a request has no explicit receiver, there's no guarantee
                    it'll be handled—therequest can fall off the end of the chain withoutever being
                    handled.A request can also go unhandled when the chain is not configured properly.</li>
            </ol>
        </p>
    </div>
    <div class="section">
        <h2>
            Related Patterns</h2>
        <p>
            <ul>
                <li><a href="">Chain</a> of Responsibility is often applied in conjunction with <a href="">Composite</a>. There, a
                    component's parent can act as its successor. </li>
            </ul>
        </p>
    </div>
</body>
</html>
